Skip to main content

sc.json

The JSON Module for the computer API!


Functions

isSafe

sc.json.isSafe( root )

Returns true if a lua table is safe to convert to JSON.

Arguments:

  • root [ table ] The lua table to check.

Returns:

  • [ boolean ] Returns true if the data is safe for conversion to json.

toString

sc.json.toString( root, prettify, indent )

Converts a lua table to a JSON string.

Arguments:

  • root [ table ] The lua table to convert to a string.
  • prettify [ boolean? ] If true, The JSON string would be prettier. Use this when you want to display it to the user.
  • indent [ string? ] The indentation character. Defaults to "\t"

Returns:

  • [ string ] The JSON string from a Lua table.

prettifyTable

sc.json.prettifyTable( rootContents )

Adds syntax highlighting to the JSON tab. Content is automatically prettified.

Arguments:

  • rootContents [ table|string|number|boolean|nil ] The root contents to format.

Returns:

  • [ string ] The prettified JSON-like formatted string.

prettifyString

sc.json.prettifyString( root )

Prettifies a JSON string by parsing it into a table and passing it into prettifyTable.

Arguments:

  • root [ string ] The raw JSON string.

Returns:

  • [ string ] The prettified result.

toJsonCompatibleTable

sc.json.toJsonCompatibleTable( tbl )

Cleans a table by removing all values that cannot be represented in JSON.

Arguments:

  • tbl [ table ] The table to clean. (It will be modified.)

Returns:

  • [ table ] The cleaned table.